home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / Imageer 1.0.0d3 / source / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  24.1 KB  |  974 lines  |  [TEXT/MPS ]

  1. /****************************************************/
  2. /*                                                    */
  3. /*    File:        menu.c                                */
  4. /*                                                    */
  5. /*    Program:    Imageer                                */
  6. /*                                                    */
  7. /*    By:            Jason Hodges-Harris                    */
  8. /*                                                    */
  9. /*    Created:    26/10/95  00:00:00 AM                */
  10. /*                                                    */
  11. /*    Version:    1.0.0d3                                */
  12. /*                                                    */
  13. /*    Copyright:    © 1995-96 Apple Computer, Inc.,        */ 
  14. /*                    all rights reserved.            */        
  15. /*                                                    */
  16. /****************************************************/
  17.  
  18.  
  19. /**** Macintosh Toolbox Headers *****/
  20.  
  21. #ifndef __DESK__
  22. #include <Desk.h>
  23. #endif
  24.  
  25. #ifndef __ERRORS__
  26. #include <Errors.h>
  27. #endif
  28.  
  29. #ifndef __GXENVIRONMENT__
  30. #include <GXEnvironment.h>
  31. #endif
  32.  
  33. #ifndef __MEMORY__
  34. #include <Memory.h>
  35. #endif
  36.  
  37. #ifndef __MENUS__
  38. #include <Menus.h>
  39. #endif
  40.  
  41. #ifndef __QUICKDRAW__
  42. #include <QuickDraw.h>
  43. #endif
  44.  
  45. #ifndef __TEXTUTILS__
  46. #include <TextUtils.h>
  47. #endif
  48.  
  49. #ifndef __TOOLUTILS__
  50. #include <ToolUtils.h>
  51. #endif
  52.  
  53. #ifndef __WINDOWS__
  54. #include <Windows.h>
  55. #endif
  56.  
  57.  
  58. /****   Application headers and prototypes   ****/
  59.  
  60.  
  61. #ifndef __IMAGEERAPPHEADER__
  62. #include "Imageer.app.h"
  63. #endif
  64.  
  65. #ifndef __IMAGEERPROTOSHEADER__
  66. #include "Imageer.protos.h"
  67. #endif
  68.  
  69.  
  70. /***** Global Variables *****/
  71.  
  72. extern Boolean            gDone;                    // program loop test condition
  73. extern Boolean            gQDGXtrue;                // QuickDraw GX present
  74. extern short            gNumOpenWindows;        //    number of open document windows
  75.  
  76. // Initialise the application menubar.
  77.  
  78. #pragma segment Menu
  79. void MenuBarInit (void)
  80. {
  81.     SetMenuBar (GetNewMBar(rMenuBar));
  82.     AddResMenu (GetMHandle(mApple),'DRVR');
  83.     AddSubMenu(mBrightness);
  84.     AddSubMenu(mContrast);
  85.     AddSubMenu(mColor);
  86.     DrawMenuBar();
  87. }
  88.  
  89.  
  90. // Sets the menubar to the default settings during the application initialisation phase.
  91.  
  92. #pragma segment Menu
  93. void    DoAdjustMenus(void)
  94. {
  95.         DoAdjustFileMenu();
  96.         DoAdjustEditMenu();
  97.         DoAdjustWindowsMenu();
  98.         DoAdjustFilterMenu();
  99.         DoAdjustEffectsMenu();
  100.         DoAdjustModelMenu();
  101.         DrawMenuBar();
  102.     return;
  103. }
  104.  
  105.  
  106. // The DoMenuCommand() function performs all of the handling of 
  107. // the user's interaction with the application
  108.  
  109. #pragma segment Menu
  110. void    DoMenuCommand(long menuResult)
  111. {
  112.     ImageDocHndl         theWindDocHndl;
  113.     WindowPtr            oldPort,
  114.                         window,
  115.                         theNextWindow;
  116.     MenuHandle            theMenu;
  117.     Str255                daName,
  118.                         theItemString,
  119.                         theResString;
  120.     OSErr                error = noErr;
  121.     short                menuID,
  122.                         menuItem,
  123.                         daRefNum,
  124.                         count;
  125.     
  126.     menuID   = HiWord(menuResult);
  127.     menuItem = LoWord(menuResult);
  128.  
  129.     switch (menuID) 
  130.     {
  131.  
  132.         case mApple:                // Apple menubar items
  133.             switch (menuItem) 
  134.             {
  135.                 /* Display the application about box.
  136.                    App name, copyright etc. */
  137.                 case iAbout:        
  138.                     DisplayAlert (rAboutBox,0,0);
  139.                 break;
  140.  
  141.                 // handle all menubar Desk Accessories.
  142.                 default:            
  143.                     GetItem(GetMHandle(mApple), menuItem, daName);
  144.                     daRefNum = OpenDeskAcc(daName);
  145.                 break;
  146.             }
  147.         break;
  148.  
  149.         case mFile:                        // File menubar items
  150.             switch (menuItem) 
  151.             {
  152.                 case iOpen:
  153.                     theMenu = GetMHandle(mModel);
  154.                     GetMenuItemText(theMenu,iUseQDGX,theItemString);    
  155.                     GetIndString (theResString,rImageModel,iUseQuickDrawGX);
  156.                     if (!EqualString(theItemString,theResString,true,true))
  157.                         SetMenuItemText (theMenu,iUseQDGX,theResString);    // reset menu item
  158.                     /**** default to Color QD. QDGX file type not yet supported for file load ****/
  159.                     error = LoadSupportedImage();
  160.                     if (!error)
  161.                     {
  162.                         if (ColorWindowVisible())
  163.                         {
  164.                             window = FrontWindow();
  165.                             theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  166.                             UpdateColorsWindPalette(theWindDocHndl, window);
  167.                         }
  168.                         theMenu = GetMHandle(mFile);
  169.                         if (((**theMenu).enableFlags & 4) == 0)    // test if Close menu item enabled
  170.                         {
  171.                             EnableItem(theMenu,iClose);
  172.                             EnableItem(theMenu,iCloseAll);
  173.                             EnableItem(theMenu,iSaveAs);
  174.                             EnableItem(theMenu,iRevert);
  175.                             EnableItem(GetMHandle(mWindow),iColors);
  176.                             theMenu = GetMHandle(mFilters);
  177.                             for (count = iSmoothFilter;count <= iHiPassFilter; ++count)
  178.                                 EnableItem(theMenu,count);
  179.                             theMenu = GetMHandle(mEffects);
  180.                             for (count = iInvert;count <= iRotate180; ++count)
  181.                                 EnableItem(theMenu,count);
  182.                         }
  183.                     }
  184.                 break;
  185.                 case iClose:
  186.                     window = FrontWindow();
  187.                     if (window)
  188.                         DisposeImageWindow (window);
  189.                 break;
  190.                 case iCloseAll:
  191.                     window = FrontWindow();
  192.                     while (window)
  193.                     {
  194.                         theNextWindow = &((WindowPeek)window)->nextWindow->port;
  195.                         DisposeImageWindow (window);
  196.                         window = theNextWindow;
  197.                     }
  198.                 break;
  199.                 case iSave:
  200.                     window = FrontWindow();
  201.                     if (window)
  202.                     {
  203.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  204.                         if (!(**theWindDocHndl).isColorsWindow)
  205.                             error = SaveSupportedImageFile(theWindDocHndl);
  206.                     }
  207.                 break;
  208.                 case iSaveAs:
  209.                     window = FrontWindow();
  210.                     if (window)
  211.                     {
  212.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  213.                         if (!(**theWindDocHndl).isColorsWindow)
  214.                             error = SaveSupportedImageFile(theWindDocHndl);
  215.                     }
  216.                 break;
  217.                 case iRevert:
  218.                     window = FrontWindow();
  219.                     theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  220.                     if (!(*theWindDocHndl)->isColorsWindow)
  221.                         error = RevertToSavedFile(theWindDocHndl, window);
  222.                     if (error)
  223.                         DisplayAlert(rGenWarning,rFileIOMessages,iRevertFileFail);
  224.                     if (ColorWindowVisible())
  225.                     {
  226.                         if (!(*theWindDocHndl)->isUsingQDGX)
  227.                             UpdateColorsWindPalette(theWindDocHndl, window);
  228.                     }
  229.                 break;
  230.                 case iQuit:
  231.                     window = FrontWindow();
  232.                     while (window)
  233.                     {
  234.                         DisposeImageWindow (window);
  235.                         window = FrontWindow();
  236.                     }
  237.                     gDone=true;
  238.                 break;
  239.             }
  240.             break;
  241.  
  242.         /*  Edit menubar options. */
  243.         case mEdit:        
  244.             switch (menuItem) 
  245.             {
  246.                 case iUndo:
  247.                     window = FrontWindow();
  248.                     if (window)
  249.                     {
  250.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  251.                         if (!(**theWindDocHndl).isColorsWindow && (**theWindDocHndl).theUndoState)
  252.                         {
  253.                             if ((*theWindDocHndl)->isUsingQDGX)
  254.                             {
  255.                                 RestoreOldTransformCopy(theWindDocHndl,true);
  256.                             }
  257.                             else
  258.                             {
  259.                                 error = LoadTempImageFile(theWindDocHndl);
  260.                                 GetPort (&oldPort);
  261.                                 SetPort(window);
  262.                                 InvalRect(&window->portRect);
  263.                                 SetPort(oldPort);
  264.                                 if (ColorWindowVisible())
  265.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  266.                             }
  267.                         }
  268.                     }
  269.                 break;
  270.                 
  271.                 case iCut:
  272.                 break;
  273.                 
  274.                 case iCopy:
  275.                 break;
  276.                 
  277.                 case iPaste:
  278.                 break;
  279.             }
  280.         break;
  281.         
  282.         case mWindow:
  283.             switch (menuItem)
  284.             {
  285.                 case iColors:
  286.                 theMenu = GetMHandle(mWindow);
  287.                     if (((**theMenu).enableFlags & 1) == 1)    // test for Window menu Colors item enabled
  288.                     {
  289.                         GetMenuItemText(theMenu,iColors,theItemString);    
  290.                         GetIndString (theResString,rMenuItems,iHideColors);
  291.                         if (EqualString(theItemString,theResString,true,true))
  292.                             DisposeColorsWindow();
  293.                         else
  294.                             CreateColorsWindow();
  295.                     }
  296.                 break;
  297.                 default:
  298.                     theMenu = GetMHandle(mWindow);
  299.                     window = FrontWindow();
  300.                     while (window)
  301.                     {
  302.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  303.                         if (menuItem == (**theWindDocHndl).theMenuItem)
  304.                         {
  305.                             if (window != FrontWindow())
  306.                                 SetUndoItemText((*theWindDocHndl)->theUndoState);
  307.                             if ((*theWindDocHndl)->isUsingQDGX)
  308.                                 SetMenuItemAvailable(true);
  309.                             else
  310.                                 SetMenuItemAvailable(false);
  311.                             SetItemMark(theMenu,(**theWindDocHndl).theMenuItem,0x12);
  312.                             SelectWindow (window);
  313.                         }
  314.                         else
  315.                             SetItemMark(theMenu,(**theWindDocHndl).theMenuItem,0x00);
  316.                         theNextWindow = &((WindowPeek)window)->nextWindow->port;
  317.                         window = theNextWindow;
  318.                     }
  319.                 break;
  320.             }
  321.         break;
  322.         case mFilters:
  323.             switch (menuItem)
  324.             {
  325.                 case iSmoothFilter:
  326.                     window = FrontWindow();
  327.                     if (window)
  328.                     {
  329.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  330.                         if (!(**theWindDocHndl).isColorsWindow)
  331.                             if (!(*theWindDocHndl)->isUsingQDGX)
  332.                             {
  333.                                 SaveTempImageFile(theWindDocHndl, kPixMapOp);
  334.                                 SetUndoItemText(kCanUndo);
  335.                                 error = ImageSmoothFilter(theWindDocHndl, window);
  336.                                 if (error)
  337.                                 {
  338.                                     RemoveTempFile(theWindDocHndl, true, false);
  339.                                     SetUndoItemText(kCannotUndo);
  340.                                     (*theWindDocHndl)->theUndoState = kCannotUndo;
  341.                                 }    
  342.                                 if (ColorWindowVisible())
  343.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  344.                             }
  345.                     }
  346.                 break;
  347.                 case iHiPassFilter:
  348.                     window = FrontWindow();
  349.                     if (window)
  350.                     {
  351.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  352.                         if (!(**theWindDocHndl).isColorsWindow)
  353.                             if (!(*theWindDocHndl)->isUsingQDGX)
  354.                             {
  355.                                 SaveTempImageFile(theWindDocHndl, kPixMapOp);
  356.                                 error = ImageHiPassFilter(theWindDocHndl, window);
  357.                                 if (error)
  358.                                 {
  359.                                     RemoveTempFile(theWindDocHndl, true, false);
  360.                                     SetUndoItemText(kCannotUndo);
  361.                                     (*theWindDocHndl)->theUndoState = kCannotUndo;
  362.                                 }    
  363.                                 if (ColorWindowVisible())
  364.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  365.                             }
  366.                     }
  367.                 break;
  368.             }
  369.         break;
  370.         case mEffects:
  371.             switch (menuItem)
  372.             {
  373.                 case iInvert:
  374.                     window = FrontWindow();
  375.                     if (window)
  376.                     {
  377.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  378.                         if (!(**theWindDocHndl).isColorsWindow)
  379.                             if ((**theWindDocHndl).isUsingQDGX)
  380.                             {
  381.                                 (*theWindDocHndl)->theGXUndoType = kGXinkTransform;
  382.                                 SaveTransformCopy(theWindDocHndl, true);
  383.                                 GxShapeInkInvert (theWindDocHndl, window);        // Use QDGX
  384.                             }
  385.                             else
  386.                             {
  387.                                 error = ColorImageInverter (theWindDocHndl, window);    // Use Color QD
  388.                                 (*theWindDocHndl)->theUndoState = kCanUndo;
  389.                                 if (error)
  390.                                 {
  391.                                     RemoveTempFile(theWindDocHndl, true, false);
  392.                                     SetUndoItemText(kCannotUndo);
  393.                                     (*theWindDocHndl)->theUndoState = kCannotUndo;
  394.                                 }    
  395.                                 if (ColorWindowVisible())
  396.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  397.                             }
  398.                     }
  399.                 break;
  400.                 case iMirrorXaxis:
  401.                     window = FrontWindow();
  402.                     if (window)
  403.                     {
  404.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  405.                         if (!(**theWindDocHndl).isColorsWindow)
  406.                             if ((**theWindDocHndl).isUsingQDGX)
  407.                             {
  408.                                 (*theWindDocHndl)->theGXUndoType = kGXshapeTransform;
  409.                                 SaveTransformCopy(theWindDocHndl, true);
  410.                                 MirrorGxShape(theWindDocHndl, window, true);    // Use QDGX
  411.                             }
  412.                             else
  413.                             {
  414.                                 SaveTempImageFile(theWindDocHndl, kPixMapOp);
  415.                                 error = MirrorImageHorizontal(theWindDocHndl, window);    // Use Color QD
  416.                                 if (error)
  417.                                 {
  418.                                     RemoveTempFile(theWindDocHndl, true, false);
  419.                                     SetUndoItemText(kCannotUndo);
  420.                                     (*theWindDocHndl)->theUndoState = kCannotUndo;
  421.                                 }    
  422.                             }
  423.                     }
  424.                 break;
  425.                 case iMirrorYaxis:
  426.                     window = FrontWindow();
  427.                     if (window)
  428.                     {
  429.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  430.                         if (!(**theWindDocHndl).isColorsWindow)
  431.                             if ((**theWindDocHndl).isUsingQDGX)
  432.                             {
  433.                                 (*theWindDocHndl)->theGXUndoType = kGXshapeTransform;
  434.                                 SaveTransformCopy(theWindDocHndl, true);
  435.                                 MirrorGxShape(theWindDocHndl, window, false);    // Use QDGX
  436.                             }
  437.                             else
  438.                             {
  439.                                 SaveTempImageFile(theWindDocHndl, kPixMapOp);
  440.                                 error = MirrorImageVertical (theWindDocHndl, window);    // Use Color QD
  441.                                 if (error)
  442.                                 {
  443.                                     RemoveTempFile(theWindDocHndl, true, false);
  444.                                     SetUndoItemText(kCannotUndo);
  445.                                     (*theWindDocHndl)->theUndoState = kCannotUndo;
  446.                                 }    
  447.                             }
  448.                     }
  449.                 break;
  450.                 case iRotate180:
  451.                     window = FrontWindow();
  452.                     if (window)
  453.                     {
  454.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  455.                         if (!(**theWindDocHndl).isColorsWindow)
  456.                             if ((**theWindDocHndl).isUsingQDGX)
  457.                             {
  458.                                 (*theWindDocHndl)->theGXUndoType = kGXshapeTransform;
  459.                                 SaveTransformCopy(theWindDocHndl, true);
  460.                                 RotateGxShape(theWindDocHndl,window,ff(180)); // Use QDGX
  461.                             }
  462.                             else
  463.                             {
  464.                                 SaveTempImageFile(theWindDocHndl, kPixMapOp);
  465.                                 error = RotateImage180 (theWindDocHndl, window);        // Use Color QD
  466.                                 if (error)
  467.                                 {
  468.                                     RemoveTempFile(theWindDocHndl, true, false);
  469.                                     SetUndoItemText(kCannotUndo);
  470.                                     (*theWindDocHndl)->theUndoState = kCannotUndo;
  471.                                 }    
  472.                             }
  473.                     }
  474.                 break;
  475.             }
  476.         break;
  477.         case mBrightness:        /****    Brightness sub menu    ****/
  478.             switch (menuItem)
  479.             {
  480.                 case iLighter:
  481.                     window = FrontWindow();
  482.                     if (window)
  483.                     {
  484.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  485.                         if (!(**theWindDocHndl).isColorsWindow)
  486.                             if ((**theWindDocHndl).isUsingQDGX)
  487.                             {
  488.                                 (*theWindDocHndl)->theGXUndoType = kGXinkTransform;
  489.                                 SaveTransformCopy(theWindDocHndl, true);
  490.                                 GxShapeInkBrightness (theWindDocHndl, window, true); // Use QDGX
  491.                             }
  492.                             else
  493.                             {
  494.                                 ImageBrightness(theWindDocHndl, window,true);        // Use Color QD
  495.                                 if (ColorWindowVisible())
  496.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  497.                             }
  498.                     }
  499.                 break;
  500.                 case iDarker:
  501.                     window = FrontWindow();
  502.                     if (window)
  503.                     {
  504.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  505.                         if (!(**theWindDocHndl).isColorsWindow)
  506.                             if ((**theWindDocHndl).isUsingQDGX)
  507.                             {
  508.                                 (*theWindDocHndl)->theGXUndoType = kGXinkTransform;
  509.                                 SaveTransformCopy(theWindDocHndl, true);
  510.                                 GxShapeInkBrightness (theWindDocHndl, window, false); // Use QDGX
  511.                             }
  512.                             else
  513.                             {
  514.                                 ImageBrightness(theWindDocHndl, window,false);        // Use Color QD
  515.                                 if (ColorWindowVisible())
  516.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  517.                             }
  518.                     }
  519.                 break;
  520.             }
  521.         break;
  522.         case mContrast:        /****    Contrast sub menu    ****/
  523.             switch (menuItem)
  524.             {
  525.                 case iIncrease:
  526.                     window = FrontWindow();
  527.                     if (window)
  528.                     {
  529.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  530.                         if (!(**theWindDocHndl).isColorsWindow)
  531.                             if    (!(**theWindDocHndl).isUsingQDGX)
  532.                             {
  533.                                 ImageContrast(theWindDocHndl, window,true);
  534.                                 if (ColorWindowVisible())
  535.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  536.                             }
  537.                     }
  538.                 break;
  539.                 case iDecrease:
  540.                     window = FrontWindow();
  541.                     if (window)
  542.                     {
  543.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  544.                         if (!(**theWindDocHndl).isColorsWindow)
  545.                             if    (!(**theWindDocHndl).isUsingQDGX)
  546.                             {
  547.                                 ImageContrast(theWindDocHndl, window,false);
  548.                                 if (ColorWindowVisible())
  549.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  550.                             }
  551.                     }
  552.                 break;
  553.             }
  554.         break;
  555.         case mColor:        /****    Color Component sub menu    ****/
  556.             switch (menuItem)
  557.             {
  558.                 case iRedColorComp:
  559.                     window = FrontWindow();
  560.                     if (window)
  561.                     {
  562.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  563.                         if (!(**theWindDocHndl).isColorsWindow)
  564.                             if ((**theWindDocHndl).isUsingQDGX)
  565.                             {
  566.                                 (*theWindDocHndl)->theGXUndoType = kGXinkTransform;
  567.                                 SaveTransformCopy(theWindDocHndl, true);
  568.                                 RGBColorComponent (theWindDocHndl, window, kRedComp); // Use QDGX
  569.                             }
  570.                             else
  571.                             {
  572.                                 RemoveColorComponent(theWindDocHndl, window, kRedComp);        // Use Color QD
  573.                                 if (ColorWindowVisible())
  574.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  575.                             }
  576.                     }
  577.                 break;
  578.                 case iGreenColorComp:
  579.                     window = FrontWindow();
  580.                     if (window)
  581.                     {
  582.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  583.                         if (!(**theWindDocHndl).isColorsWindow)
  584.                             if ((**theWindDocHndl).isUsingQDGX)
  585.                             {
  586.                                 (*theWindDocHndl)->theGXUndoType = kGXinkTransform;
  587.                                 SaveTransformCopy(theWindDocHndl, true);
  588.                                 RGBColorComponent (theWindDocHndl, window, kGreenComp); // Use QDGX
  589.                             }
  590.                             else
  591.                             {
  592.                                 RemoveColorComponent(theWindDocHndl, window, kGreenComp);        // Use Color QD
  593.                                 if (ColorWindowVisible())
  594.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  595.                             }
  596.                     }
  597.                 break;
  598.                 case iBlueColorComp:
  599.                     window = FrontWindow();
  600.                     if (window)
  601.                     {
  602.                         theWindDocHndl = (ImageDocHndl)GetWRefCon(window);
  603.                         if (!(**theWindDocHndl).isColorsWindow)
  604.                             if ((**theWindDocHndl).isUsingQDGX)
  605.                             {
  606.                                 (*theWindDocHndl)->theGXUndoType = kGXinkTransform;
  607.                                 SaveTransformCopy(theWindDocHndl, true);
  608.                                 RGBColorComponent (theWindDocHndl, window, kBlueComp); // Use QDGX
  609.                             }
  610.                             else
  611.                             {
  612.                                 RemoveColorComponent(theWindDocHndl, window, kBlueComp);        // Use Color QD
  613.                                 if (ColorWindowVisible())
  614.                                     UpdateColorsWindPalette(theWindDocHndl, window);
  615.                             }
  616.                     }
  617.                 break;
  618.             }
  619.         break;
  620.         case mModel:
  621.             error = SetImagingModel();
  622.             switch (error)
  623.             {
  624.                 case kCannotConvertToGX:
  625.                     DisplayAlert(rGenWarning,rQDGXmessages,iCannotConvToGX);
  626.                 break;
  627.                 case kCannotConvertToQD:
  628.                     DisplayAlert(rGenWarning,rQDGXmessages,iCannotSwitchGX);
  629.                 break;
  630.             }
  631.         break;
  632.  
  633.     }
  634.     HiliteMenu(0);        // Unhighlight what MenuSelect (or MenuKey) hilited.
  635. }
  636.  
  637.  
  638.  
  639. /****    Adjust the file menubar items    ****/
  640.  
  641. #pragma segment Menu
  642. void    DoAdjustFileMenu(void)
  643. {
  644.     MenuHandle            menu;
  645.     short                theItem;
  646.  
  647.     menu = GetMHandle(mFile);
  648.     for (theItem = iClose;theItem<=iRevert;++theItem)
  649.         DisableItem (menu,theItem);
  650.     return;
  651. }
  652.  
  653.  
  654. /****    Adjust the Edit menu bar items. Currently as these items
  655.    are disabled as they're not supported.    ****/
  656.  
  657.  
  658. #pragma segment Menu
  659. void    DoAdjustEditMenu(void)
  660. {
  661.     MenuHandle        menu;
  662.     short            i;
  663.     
  664.     menu = GetMHandle(mEdit);
  665.     for (i = iCut; i <= iPaste; ++i)
  666.         DisableItem(menu, i);
  667.     return;
  668. }
  669.  
  670.  
  671. #pragma segment Menu
  672. void    DoAdjustWindowsMenu(void)
  673. {
  674.     DisableItem(GetMHandle(mWindow),iColors);
  675.     return;
  676. }
  677.  
  678.  
  679. #pragma segment Menu
  680. void    DoAdjustFilterMenu(void)
  681. {
  682.     MenuHandle        menu;
  683.     short            i;
  684.     
  685.     menu = GetMHandle(mFilters);
  686.     for (i = iSmoothFilter; i <= iHiPassFilter; ++i)
  687.         DisableItem(menu, i);
  688.     return;
  689. }
  690.  
  691.  
  692. #pragma segment Menu
  693. void    DoAdjustEffectsMenu(void)
  694. {
  695.     MenuHandle        menu;
  696.     short            i;
  697.     
  698.     menu = GetMHandle(mEffects);
  699.     for (i = iInvert; i <= iRotate180; ++i)
  700.         DisableItem(menu, i);
  701.     return;
  702. }
  703.  
  704.  
  705. #pragma segment Menu
  706. void    DoAdjustModelMenu(void)
  707. {
  708.     MenuHandle        menu;
  709.     
  710.     menu = GetMHandle(mModel);
  711.     /****    Disable the use QDGX menu option if not installed    ****/
  712.     if (!gQDGXtrue)
  713.         DisableItem(menu,iUseQDGX);
  714.     return;
  715. }
  716.  
  717.  
  718.  
  719. /****    Add Document Window to Window Menu list    ****/
  720.  
  721. #pragma segment Menu
  722. OSErr    AddDocNameToMenu (ImageDocHndl theWindDocHndl)
  723. {
  724.     ImageDocHndl        theFoundDocHndl;
  725.     MenuHandle            theMenu;
  726.     WindowPtr            theWindow;
  727.     WindowRecord        *theNextWindow;
  728.     OSErr                error = noErr;
  729.     
  730.     theMenu = GetMHandle(mWindow);
  731.     InsertMenuItem(theMenu,(**theWindDocHndl).theImageFileReply.sfFile.name,gNumOpenWindows+2); // place after 2 item offset
  732.     SetItemMark(theMenu,gNumOpenWindows+3,0x12);    // place tick mark against opened window menu item
  733.     if (gNumOpenWindows)
  734.     {
  735.         theWindow = FrontWindow();
  736.         theNextWindow = ((WindowPeek)theWindow)->nextWindow;
  737.         theFoundDocHndl = (ImageDocHndl)GetWRefCon(&(theNextWindow->port));
  738.         SetItemMark(theMenu,(**theFoundDocHndl).theMenuItem,0x00);
  739.     }
  740.     gNumOpenWindows++;
  741.     (**theWindDocHndl).theMenuItem = gNumOpenWindows+2; // 2 item offset as window list starts at item 3
  742.     DrawMenuBar();
  743.     return    error;
  744. }
  745.  
  746. /****    Delete Document Window from Window Menu list    ****/
  747.  
  748. #pragma segment Menu
  749. OSErr    DeleteDocNameFromMenu (ImageDocHndl theWindDocHndl)
  750. {
  751.     ImageDocHndl        theFoundDocHndl;
  752.     MenuHandle            theMenu;
  753.     WindowPtr            theWindow,
  754.                         theNextWindow;
  755.     OSErr                error = noErr;
  756.     
  757.     theMenu = GetMHandle(mWindow);
  758.     DeleteMenuItem(theMenu,(**theWindDocHndl).theMenuItem);
  759.     error = RearrangeMenuItems(theWindDocHndl);
  760.     gNumOpenWindows--;
  761.     if (gNumOpenWindows)
  762.     {
  763.         theWindow = FrontWindow();
  764.         theNextWindow = &((WindowPeek)theWindow)->nextWindow->port;
  765.         theFoundDocHndl = (ImageDocHndl)GetWRefCon(theNextWindow);
  766.         SetItemMark(theMenu,(**theFoundDocHndl).theMenuItem,0x12);
  767.     }
  768.     DrawMenuBar();
  769.     return    error;
  770. }
  771.  
  772.  
  773. /****    Rearrange items in Windows Menu list after document window closed    ****/
  774.  
  775. #pragma segment Menu
  776. OSErr    RearrangeMenuItems(ImageDocHndl theWindDocHndl)
  777. {
  778.     ImageDocHndl        theDocRefCon;
  779.     WindowPtr            theWindow,
  780.                         theNextWindow;
  781.     OSErr                error = noErr;
  782.     short                deletedItemValue;
  783.     
  784.     deletedItemValue = (**theWindDocHndl).theMenuItem;
  785.     theWindow = FrontWindow();
  786.     while (theWindow)
  787.     {
  788.         theDocRefCon=(ImageDocHndl)GetWRefCon(theWindow);
  789.         if ((**theDocRefCon).theMenuItem > deletedItemValue)
  790.             (**theDocRefCon).theMenuItem--;    
  791.         theNextWindow = &((WindowPeek)theWindow)->nextWindow->port;
  792.         theWindow = theNextWindow;
  793.     }
  794.     return    error;
  795. }
  796.  
  797.  
  798. /****    Update ticked item in Window menu list ****/
  799.  
  800. #pragma segment Menu
  801. OSErr    SetCurrentWindowMark(WindowPtr    theWindow)
  802. {
  803.     ImageDocHndl        theFoundDocHndl;
  804.     MenuHandle            theMenu;
  805.     WindowPtr            theFrontWindow;
  806.     OSErr                error = noErr;
  807.  
  808.     theFrontWindow = FrontWindow();
  809.     if(theWindow != theFrontWindow)
  810.     {
  811.         theMenu = GetMHandle(mWindow);
  812.         if (gNumOpenWindows)
  813.         {
  814.             theFoundDocHndl = (ImageDocHndl)GetWRefCon(theFrontWindow);
  815.             SetItemMark(theMenu,(**theFoundDocHndl).theMenuItem,0x00);
  816.         }
  817.         theFoundDocHndl = (ImageDocHndl)GetWRefCon(theWindow);
  818.         SetItemMark(theMenu,(**theFoundDocHndl).theMenuItem,0x12);    // place tick mark against opened window menu item
  819.     }    
  820.     return noErr;
  821. }
  822.  
  823.  
  824. /****    Place hierarchical sub menu into menu list    ****/
  825.  
  826. #pragma segment Menu
  827. void    AddSubMenu(short menuID)
  828. {
  829.     MenuHandle        theSubMenu;
  830.     
  831.     theSubMenu = GetMenu(menuID);
  832.     InsertMenu(theSubMenu,-1);
  833. }
  834.  
  835.  
  836. /****    Disable menu items for progress Dialog    ****/
  837.  
  838. #pragma segment Menu
  839. void    DisableAllMenus(Boolean    isDisabled)
  840. {
  841.     if (isDisabled)
  842.     {
  843.         DisableItem(GetMHandle(mFile),0);
  844.         DisableItem(GetMHandle(mWindow),0);
  845.         DisableItem(GetMHandle(mFilters),0);
  846.         DisableItem(GetMHandle(mEffects),0);
  847.         DisableItem(GetMHandle(mModel),0);
  848.     }
  849.     else
  850.     {
  851.         EnableItem(GetMHandle(mFile),0);
  852.         EnableItem(GetMHandle(mWindow),0);
  853.         EnableItem(GetMHandle(mFilters),0);
  854.         EnableItem(GetMHandle(mEffects),0);
  855.         EnableItem(GetMHandle(mModel),0);
  856.     }
  857.     DrawMenuBar();
  858. }
  859.  
  860.  
  861. /****    Set imaging model    ****/
  862.  
  863. #pragma segment Menu
  864. OSErr    SetImagingModel(void)
  865. {
  866.     ImageDocHndl         theDocHndl;
  867.     MenuHandle            theMenu;
  868.     WindowPtr            theWindow;
  869.     Str255                theItemString,
  870.                         theResString;
  871.     OSErr                error = noErr;
  872.  
  873.     theWindow = FrontWindow();
  874.     theMenu = GetMHandle(mModel);
  875.     GetMenuItemText(theMenu,iUseQDGX,theItemString);    
  876.     GetIndString (theResString,rImageModel,iUseQuickDrawGX);
  877.     if (theWindow)
  878.     {
  879.         theDocHndl = (ImageDocHndl)GetWRefCon(theWindow);
  880.         if (!(**theDocHndl).isColorsWindow)
  881.         {
  882.             if (!EqualString(theItemString,theResString,true,true))
  883.                 return kCannotConvertToQD;
  884.             else
  885.             {
  886.                 GetIndString (theItemString,rImageModel,iUseColorQD);
  887.                 SetMenuItemText (theMenu,iUseQDGX,theItemString);                
  888.                 (**theDocHndl).isUsingQDGX = true;
  889.                 /****    Code to Convert current window image to QDGX object    ****/                        
  890.                 /****    Create QDGX view objects    ****/
  891.                 error = CreateGXviewPorts(theDocHndl, theWindow);
  892.                 if (!error)
  893.                     error |= ConvPixMapToGXShape(theDocHndl, theWindow);
  894.                 if (error)
  895.                     error =  kCannotConvertToGX;
  896.                 else
  897.                 {
  898.                     /****    Remove color Quickdraw information not required    ****/
  899.                     if ((*theDocHndl)->theImageWorld)
  900.                         DisposeGWorld((*theDocHndl)->theImageWorld);
  901.                     if ((*theDocHndl)->hasUndoTemp)
  902.                         RemoveTempFile(theDocHndl, true, false);
  903.                     if ((*theDocHndl)->hasRedoTemp)
  904.                         RemoveTempFile(theDocHndl, false, true);
  905.                     SetMenuItemAvailable(true);
  906.                 }            
  907.             }
  908.         }
  909.     }
  910.     else
  911.     {
  912.         if (EqualString(theItemString,theResString,true,true))
  913.         {
  914.             GetIndString (theItemString,rImageModel,iUseColorQD);
  915.             SetMenuItemText (theMenu,iUseQDGX,theItemString);                
  916.             SetMenuItemAvailable(true);
  917.         }
  918.         else
  919.         {
  920.             GetIndString (theItemString,rImageModel,iUseQuickDrawGX);
  921.             SetMenuItemText (theMenu,iUseQDGX,theItemString);                
  922.             SetMenuItemAvailable(false);
  923.         }
  924.     }
  925.     return error;
  926. }
  927.  
  928.  
  929. /****    Set state of Undo menu item    ****/
  930.  
  931. #pragma segment Menu
  932. void    SetUndoItemText(short canUndo)
  933. {
  934.     MenuHandle        theMenu;
  935.     Str255            theString;
  936.     
  937.     theMenu = GetMHandle(mEdit);
  938.     switch (canUndo)
  939.     {
  940.         case kCannotUndo:
  941.             GetIndString (theString,rMenuItems,iOpCantUndo);
  942.             SetMenuItemText (theMenu,iUndo,theString);
  943.         break;
  944.         case kCanUndo:
  945.             GetIndString (theString,rMenuItems,iOpUndo);
  946.             SetMenuItemText (theMenu,iUndo,theString);
  947.         break;
  948.         case kCanRedo:
  949.             GetIndString (theString,rMenuItems,iOpRedo);
  950.             SetMenuItemText (theMenu,iUndo,theString);
  951.         break;
  952.     }
  953.     DrawMenuBar();
  954. }
  955.  
  956.  
  957. /****    Set state of supported menu items for current image window / model ****/
  958.  
  959. #pragma segment Menu
  960. void    SetMenuItemAvailable(Boolean isQDGX)
  961. {
  962.     MenuHandle        theFilterMenu;
  963.     
  964.     theFilterMenu = GetMHandle(mFilters);
  965.     if (isQDGX)
  966.     {
  967.         DisableItem(theFilterMenu, 0);
  968.     }
  969.     else
  970.     {
  971.         EnableItem(theFilterMenu, 0);
  972.     }    
  973.     DrawMenuBar();
  974. }